package com.aloda.controller.common;

import com.aloda.result.Result;
import com.aloda.service.PictureService;
import com.aloda.vo.PicUploadVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@ConditionalOnProperty(prefix = "template.LocalFileController", name = "enable", matchIfMissing = false)
public class LocalUploadController {

    @Resource
    private PictureService pictureService;

    /**
     * 管理端图片上传
     * @param file
     * @return
     */
    @PostMapping("/admin/common/upload")
    public Result<PicUploadVO> upload(MultipartFile file){
        PicUploadVO picUploadVO = pictureService.adminUpload(file);
        return Result.success(picUploadVO);
    }

    /**
     * 用户端图片上传
     * @param file
     * @return
     */
    @PostMapping("/user/common/upload")
    public Result<PicUploadVO> userUpload(MultipartFile file) {
        PicUploadVO picUploadVO = pictureService.userUpload(file);
        return Result.success(picUploadVO);
    }
}
